package com.zhiyou.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhiyou.dao.HouseMapper;
import com.zhiyou.dao.LesseeMapper;
import com.zhiyou.dao.RentMapper;
import com.zhiyou.dao.RoleMapper;
import com.zhiyou.entity.House;
import com.zhiyou.entity.Lessee;
import com.zhiyou.entity.Rent;
import com.zhiyou.entity.Role;
import com.zhiyou.service.RentService;
import com.zhiyou.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.ArrayList;
import java.util.List;

@Service
public class RoleServiceImpl implements RoleService {
    @Autowired
    RoleMapper roleMapper;
    @Override
    public PageInfo<Role> getAll(String like, Integer pageNo, Integer pageSize) {
        PageHelper.startPage(pageNo,pageSize);

        List<Role> list = roleMapper.getAll(like);
        PageInfo pageInfo= new PageInfo(list,2);
        return pageInfo;
    }

    @Override
    public int insert(String rName, String rDesc) {
        Role role = new Role();
        role.setRDesc(rDesc);
        role.setRName(rName);
        int i = roleMapper.insertSelective(role);
        return i;
    }

    @Override
    public int delete(Integer rId) {
        int i = roleMapper.deleteByPrimaryKey(rId);
        return i;
    }

    @Override
    public boolean checkRName(String rName) {
        boolean flag=false;
        Example example= new Example(Role.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("rName",rName);
        int i = roleMapper.selectCountByExample(example);
        if (i!=0){
            flag=true;
        }
        return flag;
    }

    @Override
    public Role selectOneByRId(Integer rId) {
        Role role=roleMapper.selectOneByRId(rId);
        return role;
    }

    @Override
    public int update(Role role) {
        int i = roleMapper.update(role);
        return i;
    }
}
